﻿
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>生产计划创建</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>
    <script src="~/js/framework/commonjs.js"></script>
</head>
<body>
    <ul lay-bar="disabled" class="mWebBanner">
        <li class="layui-nav-item" style="float:left;">
            <button id="btn-update" type="button" name="btn_update" onclick="saveData()" class="buttonCss">
                确认保存
            </button>
        </li>

        <li class="layui-nav-item" style="float:left;margin-left:3%">
            <button id="btn-sync" type="button" onclick="closeWin()" class="buttonCss">
                关闭页面
            </button>
        </li>
    </ul>
    <div class="layui-card" style="margin-top:10px">
        <div class="layui-card-body ">
            <form class="layui-form" id="uForm">
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="x-red">*</span>登录账号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="userCode" required lay-verify="required" autocomplete="off" class="layui-input" id="userCode" maxlength="10">
                        <input type="hidden" name="id" id="id">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>唯一且不为空
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">用户名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="userName" required lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input" id="userName" maxlength="10">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">用户部门</label>
                    <div class="layui-input-inline">
                        <select id="dept" lay-search="" name="dept" autocomplete="off"></select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">联系方式</label>
                    <div class="layui-input-inline">
                        <input type="text" name="userPhone" required lay-verify="required" placeholder="请输入电话" autocomplete="off" class="layui-input" id="userPhone">
                    </div>
                </div>
            </form>
        </div>
    </div>

</body>
</html>

<script>
    var dataId = "";
    $(function () {
        var dept = getUrlVariable("dept");
        LoadDept("dept", dept);
        dataId = getUrlVariable("dataId");
        if (dataId != "0") {
            $("input[ name='id']").val(dataId);
            EditUserLoad(dataId); //加载用户数据
        }
    })
    /**
    数据保存
    **/
    function saveData() {
        $.ajax({
            url: "../System/UpdateUser",
            data: { data: JSON.stringify(FormToJson("uForm")) },
            dataType: "json",
            type: "POST",
            success: function (rsl) {
                if (rsl.result) {
                    layer.alert("保存成功", { icon: 6 }, function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                } else {
                    layer.msg(rsl.message);
                }
            }
        });
    }

    //加载用户数据信息
    function EditUserLoad() {

        $("#userCode").attr("readonly", "readonly");
        $.ajax({
            url: "../System/getUserInfoByCode",
            type: "post",
            data: { dataId: dataId },
            success: function (rsl) {
                if (rsl.result) {
                    $.each(rsl.data[0], function (name, value) {
                        if (name != "dept") {
                            $("input[ name='" + name + "']").val(value);
                        } else {
                            $("#dept option[value='" + value + "'] ").attr("selected", true);
                            layui.use('form', function () {
                                var form = layui.form;
                                form.render();
                            });
                        }
                    });
                    //同步数据不允许修改 此处可不加
                    // if (rsl.data[0].isSync == "Y") {
                    //     $("#userName").attr("readonly", "readonly");
                    //     $("#userDep").attr("disabled", "disabled");
                    //     $("#userPhone").attr("readonly", "readonly");
                    // }

                }

            }
        });
    }
</script>


